unit IWUserS;

{
  This is a DataModule where you can add components or declare fields that are specific to
  ONE user. Instead of creating global variables, it is better to use this datamodule. You can then
  access the it using UserSession.
}
interface

uses
  IWUserSessionBase, SysUtils, Classes, DB;

type
  TIWUserSession = class(TIWUserSessionBase)
    procedure IWUserSessionBaseCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

    bAdmin, bAuth,bLogOut : Boolean;
    sDomain, sUSer : String;
    sStatus : String;
    function AuthUser( su,sd,sp : string ):boolean;
    procedure GetUser(su : String); // Retrieve user auth settings
  end;

implementation
uses IWGlobal, IWApplication, servercontroller,ActiveX,
 ActiveDS_TLB, ADShlp ; (* Uses Active Directory Helper Units  *)
  (* http://www.agnisoft.com/white_papers/active_directory.asp  *)
  
{$R *.dfm}
Procedure  TIWUserSession.GetUser( su: string );
begin
   bAuth := False;
   // Get User Credentials - user login defined in application security database
   // AD used just to auth user on network.

   //QAuth.Parameters.ParamByName('UID').Value := sUSer;
   //bAuth := True;
   try
      //QAuth.Open;
   finally

   end;

   // ****   Force
   bAuth := True;
   // Force to true since there in no query here

   (*
   if QAuth.Active then
   begin
   if QAuthUACTIVE.Value = 'Y' then
     bAuth := True
   else
     bAuth := False;
   if QAuthUADMIN.Value = 'Y' then
     bAdmin := True
   else
     bAdmin := False;
   end;
   // Set or access values etc..
   QAuth.Close;
   *)

end;
function  TIWUserSession.AuthUser( su,sd,sp : string ):boolean;
(* su - UserID
  sd - Domain
   sp - password *)
var
   iResult:Integer;
   Obj:IADs;
begin
     result := False;//ndsPassCheck('',su,sp);
//  replace D
     iResult:=ADsOpenObject('WinNT://'+sd,su,sp,ADS_SECURE_AUTHENTICATION,IADs,Obj);
     if Succeeded(iResult) then
        Result := True;
end;
procedure TIWUserSession.IWUserSessionBaseCreate(Sender: TObject);
begin
     bAuth := False;
     bLogOut := False;
     sStatus := '';

end;

end.
